import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

function r(path, name, component, children, meta) {
  return {
    path: path,
    name: name,
    component: component,
    children: children,
    meta: meta
  };
}

const routes = [
  r("/", "main", () => import("@/views/Main.vue"), null, { keepAlive: true }),
  r("/collect", "collect", () => import("@/views/Collect.vue"), null, {
    keepAlive: true
  }),
  r("/search", "search", () => import("@/views/Search.vue"), null, {
    keepAlive: true
  }),
  r("/pb", "pb", () => import("@/views/PublishTopic.vue"), null, {
    keepAlive: false
  }),
  r("/detail", "detail", () => import("@/views/TopicDetail.vue"), null, {
    keepAlive: false
  }),
  r("/video", "video", () => import("@/views/Videos.vue"), null, {
    keepAlive: true
  }),
  r("/my", "my", () => import("@/views/My.vue"), null, {
    keepAlive: true
  })
];

const router = new VueRouter({
  mode: "hash",
  routes
});

router.beforeEach((to, from, next) => {
  next();
});

export default router;
